package makecode

import (
	"gitee.com/ichub/goconfig/common/ichubconfig"
	"gitee.com/ichub/gofactroy/common/ichubbase"
	"gitee.com/ichub/gofactroy/factroy/buildfactroy"
	"gitee.com/ichub/gofactroy/factroy/dbfactroy"

	_ "github.com/go-sql-driver/mysql"

	_ "github.com/jinzhu/gorm/dialects/postgres"
)

func MakeMysql() {
	var cfg = ichubconfig.NewConfig()
	var dbClientDto = cfg.ReadIchubMysql()

	dbfactroy := &dbfactroy.DbFactroy{
		Table:        "employee",
		Author:       "leijmdas@163.com",
		Dbtype_mysql: true,
		Db:           dbClientDto.Dbname,
		ModuleName:   ichubbase.MODULE_MAP[ichubbase.APP],
		DBUrl:        dbClientDto.MakeMysqlUrl(), //"root:leijmdas@163.comL@tcp(huawei.akunlong.top:13306)/hrms?charset=utf8&mb4&parseTime=True&loc=Local",
	}

	db := dbfactroy.IniAll()
	defer db.Close()
	buildGoFactroy := &buildfactroy.BuildGoFactroy{DbFactroy: dbfactroy}
	//entity.AutoMigrate(dbcontent.GetDB())
	//单表生成
	buildGoFactroy.BuildTable()
	buildGoFactroy.BuildProto2Go()
	//全表生成
	//buildGoFactroy.BuildTables()
	////多表关联
	//func() {
	//
	//	multiQuery := &build.JoinQuery{}
	//	multiQuery.Ini(dbfactroy, "cms_column,cms_content").CheckTables()
	//	multiQuery.SelectFields("cms_column.id,cms_content.content_id")
	//	multiQuery.Keys["cms_column.id"] = "cms_content.content_id"
	//
	//	//multiQuery.Build(dbfactroy)
	//}()

	// filefactroy.InstFileFactroy.ExecPb()
}
